<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />
    <ex_super_table_page v-bind="option" ref="SuperTablePage" :autoPage="false" @selection-change="e => selection = e">
    </ex_super_table_page>

  </div>
</template>
<script>
import superTablePageFunction from '@/mixin/super-table-page-function';

import page_table_model_manage from '@/mixin/page_table_model_manage';
import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'messageManage>manage'
export default {
  title: 'label_message_manage',
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage,],
  components: {},
  data() {
    return {
      selection: [],
      option: {
        search: {
          model: [
            { key: "title", label: "label_message_title", },

            { key: "msgType", label: "label_message_type", type: 'select', enum: 'OmsBaseNotifyMsgTypeEnum' },
            { key: "status", label: "label_status", type: 'select', enum: 'OmsBaseNotifyStatusEnum' },
            {
              key: 'createDateStart', label: "label_create_time", fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'createDateEnd'
                const limitValue = data[limitKey]

                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_start_time"
                  attrs={{ type: 'datetime' }}
                  pickerOptions={{
                    disabledDate: date => { return limitValue ? (limitValue < date.getTime()) : false }
                  }}
                />)
              }

            },
            {
              key: 'createDateEnd', label: "~", fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'createDateStart'
                const limitValue = data[limitKey]
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_end_time"
                  attrs={{ type: 'datetime', 'default-time': '23:59:59' }}
                  pickerOptions={{
                    disabledDate: date => { return limitValue ? (limitValue > date.getTime()) : false }
                  }}
                />)
              }
            },
            {
              key: 'publishDateStart', label: "label_publish_time", fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'publishDateEnd'
                const limitValue = data[limitKey]

                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_start_time"
                  attrs={{ type: 'datetime' }}
                  pickerOptions={{
                    disabledDate: date => { return limitValue ? (limitValue < date.getTime()) : false }
                  }}
                />)
              }

            },
            {
              key: 'publishDateEnd', label: "~", fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'publishDateStart'
                const limitValue = data[limitKey]
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_end_time"
                  attrs={{ type: 'datetime', 'default-time': '23:59:59' }}
                  pickerOptions={{
                    disabledDate: date => { return limitValue ? (limitValue > date.getTime()) : false }
                  }}
                />)
              }
            },
          ],
        },
        action: [
          {
            label: { _key: 'label_new_any', i18n: true, type: 'label_message_notify' }, attrs: { icon: "el-icon-plus" },
            auth: 'oms_message_manage_edit',
            click: () => {
              this.$router.push({ path: '/page/oms/setting/messageCenter/messageOperate', query: { emitKey, } })
            }
          },
        ],
        table: {
          url: "/oms-api/base/OmsBaseNotifyRpc/selectPage.json",
          model: this.init_table_model(),
        },
      },


    };
  },
  methods: {
    option_table_model() {
      return [
        {
          key: 'title', label: 'label_message_title', 'min-width': 140, 'show-overflow-tooltip': true,
        },
        {
          key: 'msgType', label: 'label_message_type', 'width': 140, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "OmsBaseNotifyMsgTypeEnum")
        },
        {
          key: 'status', label: 'label_status', 'width': 140, 'show-overflow-tooltip': true,
          render: (h, { row, column }) => {
            return this.$renderText(h, row[column.property], {
              enum: "OmsBaseNotifyStatusEnum",
              valueClass: row[column.property] == "PUBLISH" ? 'color_success' : row[column.property] == "CANCEL" ? 'color_danger' : ''
            })
          }
        },
        { key: 'gmtCreate', label: 'label_create_time', 'width': 140, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$dateFormat(v) },
        { key: 'creator', label: 'label_create_user', 'width': 130, 'show-overflow-tooltip': true, },
        { key: 'publishDate', label: 'label_publish_time', 'width': 140, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$dateFormat(v) },
        { key: 'publishPerson', label: 'label_publish_user', 'width': 130, 'show-overflow-tooltip': true, },
        {
          type: 'operate', width: 210, fixed: "right", operate: [
            {
              label: "label_edit", if: (row) => !["PUBLISH", 'CANCEL'].includes(row.status),
              auth: 'oms_message_manage_edit',
              click: (row) => {
                this.$router.push({ path: '/page/oms/setting/messageCenter/messageOperate', query: { id: row.id, emitKey, } })
              }
            },
            {
              label: 'label_publish', if: (row) => !["PUBLISH", 'CANCEL'].includes(row.status),
              auth: 'oms_message_manage_publish',
              type: "confirm-button", url: '/oms-api/base/OmsBaseNotifyRpc/publishNotify.json', urlType: "json",
              message: 'tip_confirm_start_publish',
              params: (row) => { return { "id": row["id"] } }, done: ['reload', 'tip']
            },
            {
              label: 'label_close', if: (row) => !['CANCEL'].includes(row.status),
              auth: 'oms_message_manage_publish',
              type: "confirm-button", url: '/oms-api/base/OmsBaseNotifyRpc/cancelNotify.json', urlType: "json",
              message: 'tip_confirm_close_notify',
              buttonClass: "button_text_danger", confirmButtonType: 'danger',
              params: (row) => { return { "id": row["id"] } }, done: ['reload', 'tip']
            },

          ]
        },
      ]
    },


  }
};

</script>
<style></style>
